package com.yaorange.teaching.mapper;

import java.time.LocalDate;
import java.util.List;

import com.yaorange.teaching.bo.DailyTaskSubmitCountBo;
import com.yaorange.teaching.domain.YaDailyTasks;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 每日任务Mapper接口
 *
 * @author ruoyi
 * @date 2024-11-22
 */
public interface YaDailyTasksMapper extends BaseMapper<YaDailyTasks>
{
    /**
     * 查询每日任务
     *
     * @param id 每日任务主键
     * @return 每日任务
     */
    public YaDailyTasks selectYaDailyTasksById(Long id);

    /**
     * 查询每日任务列表
     *
     * @param yaDailyTasks 每日任务
     * @return 每日任务集合
     */
    public List<YaDailyTasks> selectYaDailyTasksList(YaDailyTasks yaDailyTasks);

    /**
     * 新增每日任务
     *
     * @param yaDailyTasks 每日任务
     * @return 结果
     */
    public int insertYaDailyTasks(YaDailyTasks yaDailyTasks);

    /**
     * 修改每日任务
     *
     * @param yaDailyTasks 每日任务
     * @return 结果
     */
    public int updateYaDailyTasks(YaDailyTasks yaDailyTasks);

    /**
     * 删除每日任务
     *
     * @param id 每日任务主键
     * @return 结果
     */
    public int deleteYaDailyTasksById(Long id);

    /**
     * 批量删除每日任务
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteYaDailyTasksByIds(Long[] ids);

    @Update("update  ya_daily_tasks set qualified = 1 where STATUS = 3 and date = #{yesterday}")
    void updateYaDailyTasksCompleted(@Param("yesterday") String yesterday);

    @Update("update  ya_daily_tasks set qualified = 2 ,status = 4  where STATUS < 3 and date = #{yesterday}")
    void updateYaDailyTasksExpired(@Param("yesterday")String yesterday);

    List<YaDailyTasks> selectInterviewList(@Param("date")String date, @Param("classesId")Long classesId);

    @Select("SELECT\n" +
            "\t  CASE \n" +
            "        WHEN status != 3 THEN '未提交'\n" +
            "\t\t    ELSE '已提交'\n" +
            "    END AS name,count(id) value\n" +
            "FROM\n" +
            "\tya_daily_tasks\n" +
            "WHERE\n" +
            "\tya_daily_tasks.classes_id = #{classesId} and date = #{date} group by name")
    List<DailyTaskSubmitCountBo> selectSubmitCount(@Param("classesId")Long classesId,@Param("date")String date);

}
